<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>

    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理
            <small>预约列表</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="订单编号/用户名/体检日期" v-model="pagination.queryString" style="width: 300px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button type="primary" class="butT" @click="findPage()">查询</el-button>

            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="id" label="订单编号" align="center"></el-table-column>
                <el-table-column prop="member" label="用户名" align="center"></el-table-column>
                <el-table-column prop="setmeal" label="所选套餐" align="center"></el-table-column>
                <el-table-column prop="orderDate" label="体检日期" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="orderStatus" label="套餐状态" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑预约项" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs type="card">
                            <el-form label-position="right" label-width="100px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="订单编号">
                                            <el-input v-model="formData.id" :disabled="true"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="用户名">
                                            <el-input v-model="formData.member" :disabled="true"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>

                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="编辑套餐">
                                            <el-select v-model="formData.setmeal" placeholder="请选择套餐">
                                                <el-option
                                                        v-for="item in options"
                                                        :key="item.value"
                                                        :label="item.label"
                                                        :value="item.label">
                                                </el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="预约类型">
                                            <el-select v-model="formData.orderType">
                                                <el-option label="微信预约" value="微信预约"></el-option>
                                                <el-option label="电话预约" value="电话预约"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="套餐状态">
                                            <el-select v-model="formData.orderStatus">
                                                <el-option label="未到诊" value="未到诊"></el-option>
                                                <el-option label="已到诊" value="已到诊"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="体检日期">
                                            <el-date-picker
                                                    v-model="formData.orderDate"
                                                    type="date"
                                                    format="yyyy-MM-dd"
                                                    :picker-options="pickerOptions"
                                                    value-format="yyyy-MM-dd"
                                                    placeholder="选择日期">
                                            </el-date-picker>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>


<script>
    var vue = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryString: null,
            },
            options: [],
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData: [],//新增和编辑表单中对应的检查项列表数据
            dialogFormVisible4Edit: false,//控制编辑窗口显示/隐藏
            backendUrl: "http://localhost:82",
            pickerOptions: {
                disabledDate(time) {
                    return time.getTime() < Date.now();
                }
            }
        },
        created() {
            this.findPage();
        },
        methods: {
            //编辑
            handleEdit() {

                axios.post(this.backendUrl + "/order/edit.do", this.formData).then((res) => {
                    this.$message({
                        message: res.data.message,
                        type: res.data.flag ? "success" : "error"

                    });
                    this.findPage();

                }).catch((err) => {
                    console.log(err);
                });
                this.resetForm();
                this.dialogFormVisible4Edit = false;

            },
            //分页查询
            findPage() {
                //1. 条件分页查询，将页面设置为第1页
                if (this.pagination.queryString != null && this.pagination.queryString.length > 0) {
                    this.pagination.currentPage = 1;
                }
                //2. 封装查询参数
                var params = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };

                //3. 发送ajax请求

                axios.post(this.backendUrl + "/order/findOrderListByPage.do", params).then((res) => {

                    this.pagination.total = res.data.total;

                    this.dataList = res.data.rows;
                }).catch((err) => {
                    console.log(err)
                })
            },
            // 重置表单
            resetForm(formName) {
                // 重置提示信息
                if (this.$refs[formName] != null) {
                    this.$refs[formName].resetFields();
                }
                this.formData = {};
            },
            // 弹出编辑窗口
            handleUpdate(row) {
                this.dialogFormVisible4Edit = true;
                this.resetForm();
                axios.get(this.backendUrl + "/order/findOrderById.do?id=" + row.id).then((res) => {
                    this.formData = res.data.data;
                });

                axios.get(this.backendUrl + "/setmeal/findAll.do").then((res) => {
                    this.options = res.data.data

                }).catch((err) => {
                    console.log(err);
                })

            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            // 删除
            handleDelete(row) {
                //1. 弹出警告框
                this.$confirm('此操作将永久删除该检查组, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //2 用户点击确定删除，发送ajax请求
                    axios.get(this.backendUrl + "/order/delOrderById.do?id=" + row.id).then((res) => {

                        this.$message({
                            type: res.data.flag ? 'success' : "error",
                            message: res.data.message
                        });
                        //3 页面删除成功，刷新页面
                        this.findPage();

                    }).catch((err) => {
                        console.log(err)
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });

            }
        }
    })
</script>
</html>
